package com.yuanluludev.lib_base.base

import android.os.Bundle
import android.view.*
import androidx.lifecycle.ViewModelProvider

/**
 * 带网络的弹窗基类
 * yuanLuLu
 */
abstract class BaseVMDialogFragment<VM : BaseViewModel> :
    BaseDialogFragment() {

    protected lateinit var mViewModel: VM

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        useDataBinding(true)
        return super.onCreateView(inflater, container, savedInstanceState)
    }

    override fun initViewModel() {
        mViewModel = ViewModelProvider(this).get(viewModelClass())
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        observe()

    }

    open fun observe() {
        //  override if need
    }

    /**
     * 获取ViewModel的class
     */
    abstract fun viewModelClass(): Class<VM>

}